package com.wxtt.android.dialog;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.wxtt.android.R;

/**
 * 说明：等待加载框
 * <p/>
 * 作者：fanly
 * <p/>
 * 时间：2015/12/31 16:33
 * <p/>
 * 版本：verson 1.0
 */
public class LoadingDialog extends BaseDialog{

    private View view;
    private TextView tv_msg;

    public LoadingDialog(Context context) {
        super(context);
    }

    @Override
    public int setDialogView() {
        return R.layout.dialog_loading;
    }

    @Override
    public void onInit() {
        view = getDialogView();
        tv_msg = (TextView) view.findViewById(R.id.tv_msg);
        setCancel(true);
        setText("");
    }

    /**
     * 说明：设置文本信息
     * @param msg
     * @return
     */
    public LoadingDialog setText(String msg){
        if (TextUtils.isEmpty(msg)){
            tv_msg.setVisibility(View.GONE);
        }else {
            tv_msg.setText(msg);
            tv_msg.setVisibility(View.VISIBLE);
        }
        return this;
    }

    /**
     * 说明：设置文本信息
     * @param resId
     * @return
     */
    public LoadingDialog setText(int resId){
        if (resId == 0){
            tv_msg.setVisibility(View.GONE);
        }else {
            tv_msg.setText(resId);
            tv_msg.setVisibility(View.VISIBLE);
        }
        return this;
    }

    /**
     * 说明：设置文本颜色
     * @param color
     * @return
     */
    public LoadingDialog setTextColor(int color){
        tv_msg.setTextColor(color);
        return this;
    }

    /**
     * 说明：设置返回键是否可以取消
     * @param cancel
     * @return
     */
    public LoadingDialog setCancel(boolean cancel){
        setCancelable(cancel);
        return this;
    }

    /**
     * 说明：设置点击空白是否可以取消
     * @param outside
     * @return
     */
    public LoadingDialog setCancelOnTouch(boolean outside){
        setCanceledOnTouchOutside(outside);
        return this;
    }
}
